package com.netty.reactot.reactorthread;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class MultAcceptor implements Runnable{
    private Selector selector;
    private ServerSocketChannel serverSocketChannel;
    public MultAcceptor(Selector selector, ServerSocketChannel serverSocketChannel) {
        this.selector=selector;
        this.serverSocketChannel=serverSocketChannel;
    }

    @Override
    public void run() {
        System.out.println("线程名称："+Thread.currentThread().getName());
        try {
            SocketChannel channel = serverSocketChannel.accept();//得到一个客户端连接
            channel.configureBlocking(false);
            //注册一个读事件
            channel.register(selector,SelectionKey.OP_READ,new MultHander(channel));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
